/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 *
 * $Id: EnvironmentMeasurementData.hpp,v 1.4 2009-12-08 10:48:28 morsko Exp $
 * 
 * \file
 * \brief Protocol encoder/decoder header for the EnvironmentMeasurement protocol.
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef _MACI_ENVIRONMENTMEASUREMENTDATA_HPP_
#define _MACI_ENVIRONMENTMEASUREMENTDATA_HPP_
#include "EnvironmentMeasurementTypes.hpp"
#include "MaCIData.hpp"
#include "common/timestamp.hpp"
#ifndef DISABLE_MACI_ENVIRONMENTMEASUREMENT_EXTERNAL_CONVERSIONS
#include "EnvironmentMeasurement2D.h"
#endif
#include <vector>
#include <map>

namespace gim {
  namespace binbag{class CBinBag;}
}

namespace MaCI {
  namespace EnvironmentMeasurement {

    /** EnvironmentMeasurement protocol parser.
     *
     * This class contains the methods for decoding/encoding a 
     * EnvironmentMeasurement message.
     */
    class CEnvironmentMeasurementData : public CMaCIData
    {
    public:
      CEnvironmentMeasurementData();
      ~CEnvironmentMeasurementData();

      // Copy constructor.
      CEnvironmentMeasurementData(const CEnvironmentMeasurementData &);

      // Assignment operator.
      CEnvironmentMeasurementData &operator=(const CEnvironmentMeasurementData &);

      // Interface for moving data around
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag);
      void Reset();
      void Print(const int level) const;


      /** Set timestamp element.
       *
       * @param aStamp          TTimestamp structure to set
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       * 
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);


      /** Set command element.
       * This function stores a element of type TCommand.
       *
       * @param aCmd            TCommand structure to set
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetCommand(const TCommand &aCmd);

#ifndef DISABLE_MACI_ENVIRONMENTMEASUREMENT_EXTERNAL_CONVERSIONS
      /** Set Position 2D Element
       * 
       * This function stores a element of type TPose2D
       *
       * @param aEMeasurement2D Pointer to CEnvironmentMeasurementData to set.               
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetEnvironmentMeasurement( CEnvironmentMeasurement2D *aEMeasurement2D);
    

      /** Get pointer to TEnvironmentMeasurementEvent element.
       *
       * @param aEMeasurement2D  Pointer to where CEnvironmentMeasurementData is saved.
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      bool GetEnvironmentMeasurement(CEnvironmentMeasurement2D *aEMeasurement2D) const;
#endif
      /** Set Position 2D Element
       * 
       * This function stores a element of type TPose2D
       *
       * @param aPose           TPose structure to set
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetPose2D(const TPose2D &aPose);


      /** Set Variance 2D Element
       * 
       * This function stores a element of type TVariance2D
       *
       * @param aVar            TVariance2D-structure to set
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetVariance2D(const TVariance2D &aVar);
      
      /** Set Probability Element
       * 
       * This function stores a element of type TProbability
       *
       * @param aProb           TProbability-structure to set
       * @return                'true' if element was succesfully added,
       *                        'false' if element already exists.
       */
      bool SetProbability(const TProbability &aProb);

      /** Get pointer to TTimestamp element.
       * 
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const MaCI::Common::TTimestamp *GetTimestamp(void) const;
      

      /** Get pointer to TCommand element.
       *
       * @return                 Pointer to element if such exists, 
       *                         NULL if element doesn't exists in the
       *                         container.
       */
      const TCommand *GetCommand(void) const;


     

      const TPose2D *GetPose2D(void) const;
      const TVariance2D *GetVariance2D(void) const;
      const TProbability *GetProbability(void) const;
    private:
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to timestamp if exists
      const TCommand *iCommandPtr; ///< Pointer to command if any.


      const gim::binbag::TBinBlob *iEnvironmentMeasurementPtr;
      const TEnvironmentMeasurementHeader *iEnvironmentMeasurementHeaderPtr;

      const TPose2D *iPosePtr; ///< Pointer to position if exists
      const TVariance2D *iVariancePtr;
      const TProbability *iProbabilityPtr;

    };
    
  }
}

#endif
